import http from "./http"
import _store from "../../store"
import {setDefaultCurStore} from "@/common/js/store.js"
function getLocation(){
	let location = _store.getters['user/location']  
	uni.getLocation({
		type: 'gcj02',
		isHighAccuracy: true,
		success(res) {
			let {
				latitude,
				longitude
			} = res

			if (location.latitude != latitude || location.longitude != longitude) {
				_store.commit("user/location",{latitude,longitude})
				geocoder(latitude, longitude)
			}
		},
		fail(error) {
			//拒绝授权定位
			console.log(error)
		}
	})
}
function geocoder(latitude, longitude) {
	let _this = this
	http.get('meet.index/geocoder', {
		location: latitude + ',' + longitude
	}).then(res => {
		if (res.code == 1) {
			_store.commit("user/location",{
				city_name: res.data.geo.address_component.city,
				city_row: res.data.dbRow
			})
			setDefaultCurStore()
		}
	}, fail => {})
}
export {geocoder,getLocation}
